package com.fanshuai.springcloud.controller;

import com.fanshuai.springcloud.domain.User;
import com.fanshuai.springcloud.service.UserService;
import com.fanshuai.springcloud.client.uservice.UserServiceClient;
import com.fanshuai.springcloud.web.response.CallResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController implements UserServiceClient {
    @Resource
    private UserService userService;

    @GetMapping("/user/list")
    @Override
    public CallResult<List<User>> list() {
        return new CallResult<>(userService.list());
    }

    @GetMapping("/user/get")
    @Override
    public CallResult<User> one(long userId) {
        return new CallResult<>(userService.get(userId));
    }

    @PostMapping("/user/add")
    @Override
    public CallResult<Boolean> add(User user) {
        userService.add(user);
        return new CallResult<>(true);
    }

    @PostMapping("/user/delete")
    @Override
    public CallResult<Boolean> delete(long userId) {
        userService.delete(userId);
        return new CallResult<>(true);
    }
}
